#ifndef _COMDATA_VENTRY_20120410_H_
#define _COMDATA_VENTRY_20120410_H_


#include "serialport.h"


#define MAX_COM_PORT 256
#define MAX_MODULE 1024

typedef struct tag_stModule
{
	int modid;
	int comport;
	int comaddr;
	double d[8];
}stModule;


class CComData
{
private:
	CSerialPort m_serialPort;
private:
	int m_comport;
	int m_baud;
	int m_parity;
	int m_databit;
	int m_stopbit;
private:
	int SendBuff(char* buff, int len);
	int RecvBuff( char* buff, int len );
public:
	CComData(int comport,int baud,int parity,int databit,int stopbit);
	CComData();
	virtual ~CComData();

	int OpenConn(int comport,int baud,int parity,int databit,int stopbit);
	int CloseConn();

	int GetData( char *sendbuff, int sendlen, char * recvbuff,int recvlen );	
	int GetData8( char *sendbuff, int sendlen, double * parray,int arraylen );
	int GetPortNum();
};


class CComManager
{
public:
	CComManager();
	virtual ~CComManager();	
public:
	int InitAllComport();
	int AddComport(int comport,int baud,int parity,int databit,int stopbit);

	int GetComCount();
	int GetData8( int comport,int addr, double * parray,int arraylen );

private:
	CComData m_comports[MAX_COM_PORT];
	int m_comportNumber;	
};


class CModuleManager
{
public:
	CModuleManager();
	virtual ~CModuleManager();	
public:
	int InitAllModule();
	int AddModule(stModule mod);
	
	int GetModuleCount();
	stModule GetModule(int i);
	void SetModuleD8(int i,double d8[]);
private:
	stModule m_module[MAX_MODULE];
	int m_moduleNumber;	
};


extern CComManager g_comMan;
extern CModuleManager g_modMan;


#endif //_COMDATA_VENTRY_20120410_H_